package com.songlanyun.modules.account.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.songlanyun.common.enums.GoodsConstant;
import com.songlanyun.common.enums.MemberConstant;
import com.songlanyun.modules.account.entity.AccountEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.songlanyun.modules.account.entity.UserInfoEntity;
import com.songlanyun.modules.account.entity.UserServiceAreaEntity;
import com.songlanyun.modules.account.model.dto.ImportUserDTO;
import com.songlanyun.modules.account.model.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.mapping.ResultSetType;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 会员帐号表（会员的基本信息与关系）
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-02 15:51:10
 */
@Mapper
public interface AccountDao extends BaseMapper<AccountEntity> {

    /**
     * 根据openId获取微信用户信息
     *
     * @param openId
     * @return
     */
    AccountEntity getAccountByOpenId(String openId);

    List<Long> getSubordinate(String parentPath, Long subjectionShopId);

    List<AccountEntity> selectAllPage(Map<String, Object> params);

    Long getNumByUserId(Long userId);

    IPage<AccountVO> accountPage(IPage<AccountVO> page, @Param("vo") Map<String, Object> params);

    IPage<AccountVO> accountPage2(IPage<AccountVO> page, @Param("vo") Map<String, Object> params);

    IPage<AccountVO> queryShopMemberPage(IPage<AccountVO> page, @Param("vo") Map<String, Object> params);

    IPage<AccountVO> queryUserShopRolePage(IPage<AccountVO> page, @Param("vo") Map<String, Object> params);

    AccountInfoVO getAllById(Long id);

    UserInfoEntity getUserInfoByCode(String invitationCode);

    List<Long> getDownMember(Long id);

    List<AccountDownVO> getDownById(Long id);

    void lastLoginTime(Long id);

    List<AccountParentVO> getAllParentUser(@Param("parentPathArr") List<Long> parentPathArr);

    List<AccountParentVO> getAllParentUserAndLevel(@Param("parentPathArr") List<Long> parentPathArr, @Param("shopId") Long shopId);

    AccountVO getAccountInfo(Long userId);

    int myPartnerNum(Long userId);

    AccountVO getShopAccountInfo(Long userId, Long shopId);

    UserInfoEntity getUserInfoByShopId(Long id);

    void saveQrcode(AccountEntity account);

    void saveAll(@Param("list") List<ImportUserDTO> list, @Param("ptShopId") Long ptShopId, @Param("ptUserId") Long ptUserId);

    List<AccountExportVO> exportList(@Param("vo") Map<String, Object> params);

    List<AccountExportVO> exportList2(@Param("vo") Map<String, Object> params);

    List<AccountVO> shopMemberExportList(@Param("vo") Map<String, Object> params);

    void updateSubShopIdByIds(List<Long> ids, Long shopId);

    List<Long> listByParentPath(String parentPath);

    List<Long> getAllMemberId();

    AccountAppVO appInfo(Long userId, Long shopId);

    Integer selectMemberNum(@Param("shopId") Long shopId, @Param("type") Integer type);

    void replaceParentPath(@Param("downParentPath") String downParentPath, @Param("parentPath") String parentPath, @Param("newParentPath") String newParentPath);

    OperatingCenterVO operatingCenterInfo(Long userId);

    CenterSettingVO centerSettingInfo(Long userId);

    AccountAppVO appAccountInfo(Long userId);

    AccountParentVO selectOneByArea(@Param("areaType") Integer areaType, @Param("code") String code);

    Integer getAllActivatingCount(@Param("userId") Long userId);

    Integer getChildActivatingCount(@Param("userId")Long userId);

    @Options(resultSetType = ResultSetType.FORWARD_ONLY, fetchSize = Integer.MAX_VALUE)
    List<AccountEntity> getAllActivatingUsers();

    AccountAppVO getByShareCode(String invitationCode);

    List<Long> getDownAllUserIds(@Param("userId")Long userId);

    List<AccountEntity> getNullAccoutAddressUsers(Integer limit);
    List<HashMap<String,Object>> updateTeamLevelSelect();
    Integer selectTeamById(String id);
    Integer updateUserGrade(Integer id);
    List<AccountEntity> selectUserInviteByUserId(Long userId);

    boolean updateUserPersonalPerformance(@Param("userId") Long id, @Param("personalPerformance")BigDecimal personalPerformance);
}
